package com.maiji.cloud.controller.login;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.entities.login.ShareWeightRuleEntity;
import com.maiji.cloud.request.BaseInputDto;
import com.maiji.cloud.request.IdInputDto;
import com.maiji.cloud.request.login.UploadLocationReqDto;

import java.util.List;

import com.maiji.cloud.response.login.*;
import com.maiji.cloud.response.shopingmall.TaskListResData;
import com.maiji.cloud.utils.CommonIntValueEnum;
import com.maiji.cloud.utils.Unlogin;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.login.AdviceFeedbackListReqData;
import com.maiji.cloud.request.login.AdviceFeedbackReqData;
import com.maiji.cloud.request.login.ForwardingRecordsHelpReqDto;
import com.maiji.cloud.request.login.ForwardingRecordsReqDto;
import com.maiji.cloud.request.login.GetKetonuriaResData;
import com.maiji.cloud.request.login.RecordStageReqDataDto;
import com.maiji.cloud.request.login.RecordWeightReqDto;
import com.maiji.cloud.request.login.SetPayPasswordReqData;
import com.maiji.cloud.request.login.SetUserInfoReqDto;
import com.maiji.cloud.request.login.UpdatePayPasswordReqData;
import com.maiji.cloud.request.login.UpdateUserInfoReqDto;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseOutPutDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.Status;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = {"用户信息模块"})
@RequestMapping("/userInterface/")
public class UserController extends BaseController {
	
	/**
	 * 获取任务列表
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("getTaskList")
	@ApiOperation(value = "任务列表")
	public BaseDataResDto<List<TaskListResData>> getTaskList(@RequestHeader("maijiToken") String maijiToken){
		
		return postForObjectWithToken(maijiToken,REST_URL_SHOPINGMALL + "/capital/getTaskList", null, BaseDataResDto.class);
		
		
	} 

	/**
	 * 记录体重获取减肥基金规则设置
	 * @param param
	 * @return
	 */           
	@PostMapping("addShareWeightRuleInfo")
    @ApiOperation(value = "记录体重获取减肥基金规则设置")
	public BaseResDto addShareWeightRuleInfo(@RequestBody BaseDataReqDto<ShareWeightRuleEntity> param,@RequestHeader("maijiToken")String maijiToken){
		
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/addShareWeightRuleInfo", param, BaseResDto.class);
	}

	/**
	 * 第一次使用app时设置个人基本信息
	 * @param setUserInfoReqDto
	 * @return
	 */
	@ApiOperation(value = "第一次使用app时设置个人基本信息")
	@PostMapping("setingUserInfo")
	public BaseResDto setingUserInfo(@RequestBody SetUserInfoReqDto setUserInfoReqDto, @RequestHeader("maijiToken") String maijiToken) {
		setUserInfoReqDto.getData().setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/setingUserInfo", setUserInfoReqDto,
				BaseResDto.class);

	}

    /**
     * 修改个人信息
     * @param updateUserInfoReqDto
     * @param maijiToken
     * @return
     */
	@PostMapping("updateUserInfo")
	@ApiOperation(value = "修改个人信息")
	public BaseResDto updateUserInfo(@RequestBody UpdateUserInfoReqDto updateUserInfoReqDto,@RequestHeader("maijiToken") String maijiToken ){
		updateUserInfoReqDto.getData().setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/updateUserInfo", updateUserInfoReqDto,
				BaseResDto.class);

	}

	/**
	 * 记录阶段
	 * @param maijiToken
	 * @param param
	 * @return
	 */
	@PostMapping("recordStage")
	@ApiOperation(value = "记录阶段")
	public BaseResDto recordStage(@RequestHeader("maijiToken")String maijiToken,@RequestBody BaseDataReqDto<RecordStageReqDataDto>  param){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/recordStage", param, BaseResDto.class);
	}

	/**
	 * 获得进入app设置的个人信息
	 * 
	 * @param maijiToken
	 * @return
	 */
	@ApiOperation(value = "获得进入app设置的个人信息 ")
	@PostMapping("getUserInfo")
	public UserInfoResDto getUserInfo(@RequestHeader("maijiToken") String maijiToken) {
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<>(headers);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/getUserInfo", httpEntity, UserInfoResDto.class);
	}

    /**
     * 根据用户ID获取用户信息
     * @param inputDto
     * @return
     */
	@PostMapping("getUserInfoWithUserId")
    @ApiOperation(value = "根据用户ID获取用户信息 ")
	public UserInfoResDto getUserInfoWithUserId(@RequestBody BaseInputDto<IdInputDto> inputDto,@RequestHeader(value="maijiToken",required =false)String maijiToken ){
		inputDto.getData().setToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/getUserInfoWithUserId",inputDto,UserInfoResDto.class);
	}

	/**
	 * 记录当前体重
	 * 
	 * @param recordWeightReqDto
	 * @return
	 */
	@PostMapping("recordWeight")
	@ApiOperation(value = "记录当前体重 ")
	public BaseDataResDto<RecordWeightResData> recordWeight(@RequestBody RecordWeightReqDto recordWeightReqDto, @RequestHeader("maijiToken") String maijiToken) {
		recordWeightReqDto.getData().setMaijiToken(maijiToken);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/recordWeight", recordWeightReqDto, BaseDataResDto.class);
	}

	/**
	 * 获得一个用户的所有的体重记录 
	 * @param maijiToken
	 * @return
	 */
	@ApiOperation(value = "获得一个用户的所有的体重记录 ")
	@PostMapping("getWeightChangeLogList")
	public WeightChangeLogListResDto getWeightChangeLogList(@RequestHeader("maijiToken")String maijiToken){
		
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<>(headers);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/getWeightChangeLogList", httpEntity, WeightChangeLogListResDto.class);
	}

    /**
     * 上传登录位置信息
     * @param uploadLocationReqDto
     * @param maijiToken
     * @return
     */
	@ApiOperation(value = "上传登录位置信息")
	@PostMapping("uploadLocation")
	public BaseResDto uploadLocation (@RequestBody BaseDataReqDto<UploadLocationReqDto> uploadLocationReqDto, @RequestHeader("maijiToken") String maijiToken) {
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity httpEntity = new HttpEntity(uploadLocationReqDto, headers);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/uploadLocation", httpEntity, BaseResDto.class);
	}

	/**
	 * 用户签到
	 * @param maijiToken
	 * @return
	 */
	@ApiOperation(value = "用户签到")
	@PostMapping("userSignIn")
	public BaseDataResDto<UserSignListResData> userSignIn(@RequestHeader("maijiToken") String maijiToken){
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<String>( headers);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/userSignIn", httpEntity, BaseDataResDto.class);
	}


	//今天是否签到
	@PostMapping("todaySignInResult")
	@ApiOperation(value = "今天用户是否已经签到")
	public BaseDataResDto<Boolean> todaySignInResult(@RequestHeader("maijiToken") String maijiToken){
		 return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/todaySignInResult", null, BaseDataResDto.class);
	}
	
	/**
	 * 获取用户签到记录
	 * @param maijiToken
	 * @return
	 */
	@ApiOperation(value = "获取用户签到记录")
	@PostMapping("getUserSignIn")
	public UserSignListResDto getUserSignIn(@RequestHeader("maijiToken") String maijiToken){
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<String>( headers);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/getUserSignIn", httpEntity, UserSignListResDto.class);
	}

    /**
     * 获取签到周期列表
     * @param maijiToken
     * @return
     */
	@ApiOperation(value = "获取签到周期列表")
	@PostMapping("getSignInDeployAll")
	public SignInDeployAllResDto getSignInDeployAll(@RequestHeader("maijiToken") String maijiToken) {
		HttpHeaders headers = new HttpHeaders();
		headers.add("maijiToken", maijiToken);
		HttpEntity<String> httpEntity = new HttpEntity<String>( headers);
		return restTemplate.postForObject(REST_URL_APPLOGIN + "/user/getSignInDeployAll", httpEntity, SignInDeployAllResDto.class);
	}

	/**
	 * 转发
	 * @param param
	 * @return
	 */
	@PostMapping("forwardingRecords")
	@ApiOperation(value = "转发")
	public BaseResDto forwardingRecords(@RequestBody ForwardingRecordsReqDto param,@RequestHeader("maijiToken") String maijiToken){
		   return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/forwardingRecords", param, BaseResDto.class);
	}
	
	/**
	 * 获得转发记录
	 * @param param
	 * @return
	 */
	@PostMapping("getforwardingRecordsList")
	@ApiOperation(value = "获得转发记录")
	public ForwardingRecordsListResDto getforwardingRecordsList(@RequestBody BaseDataReqDto param,@RequestHeader("maijiToken") String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/getforwardingRecordsList", param, ForwardingRecordsListResDto.class);
	}

	/**
	 * 微信用户助力
	 * @param param
	 * @return
	 */
    @Unlogin
	@PostMapping("forwardingRecordsHelp")
	@ApiOperation(value = "微信用户助力")
	public BaseResDto forwardingRecordsHelp(@RequestBody ForwardingRecordsHelpReqDto param){
		return postForObjectWithToken(null,REST_URL_APPLOGIN + "/user/forwardingRecordsHelp", param, BaseResDto.class);
	}

	/**
	 * 获取尿酮
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("getKetonuria")
	@ApiOperation(value = "获取最新尿酮记录")
	public BaseDataResDto<List<WeightChangeLogResData>> getKetonuria(@RequestBody BaseDataReqDto<GetKetonuriaResData> param, @RequestHeader("maijiToken")String maijiToken)throws Exception{
		
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/getKetonuria", param, BaseDataResDto.class);
	}
	
	/**
	 * 分享体重用户助力
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("shareWeightUserHelp")
	@ApiOperation(value = "体重记录分享之后用户助力(返回true代表本人助力)")
	public BaseDataResDto<Boolean> shareWeightUserHelp(@RequestBody BaseDataReqDto<String> param, @RequestHeader("maijiToken") String maijiToken){
		
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/shareWeightUserHelp", param, BaseDataResDto.class);
	}
	
	/**
	 * 体重分享之后点击查看详情
	 * @param param
	 * @return
	 */
	@PostMapping("getShareWeightDetails")
	@ApiOperation(value = "体重分享之后点击查看详情")
	@Unlogin
	 public BaseDataResDto<ShareWeightDetailsData> getShareWeightDetails(@RequestBody BaseDataReqDto<String> param, @RequestHeader(value="maijiToken",required =false) String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/getShareWeightDetails", param, BaseDataResDto.class);
	}
	
	/**
	 * 获取助力用户列表
	 * @param param
	 * @return
	 */
	@PostMapping("getShareWeightUserHelpList")
	@ApiOperation(value = "获取体重分享助力用户列表")
	public BaseDataResDto<List<ShareWeightUserHelpList>> getShareWeightUserHelpList(@RequestBody BaseDataReqDto<String> param, @RequestHeader(value="maijiToken",required =false) String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/getShareWeightUserHelpList", param, BaseDataResDto.class);
	}

	/**
	 * 记录尿酮
	 * @param param
	 * @param maijiToken
	 * @return
	 * @throws Exception
	 */
	@PostMapping("recordKetonuria")
	@ApiOperation(value = "记录尿酮")
	public BaseResDto recordKetonuria(@RequestBody BaseDataReqDto<String> param ,@RequestHeader("maijiToken")String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/recordKetonuria", param, BaseResDto.class);
	}

    /**
     *  获取个人中心轮播图
     * @return
     */
    @PostMapping("findUserCenterCarousel")
    @ApiOperation(value = "获取个人中心轮播图")
    public BaseDataResDto<List<UploadImageResData>>  findUserCenterCarousel (@RequestHeader("maijiToken") String maijiToken) {
        BaseDataReqDto<String> baseDataReqDto = new BaseDataReqDto<>();
        baseDataReqDto.setData("个人中心");
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/common/findAppCarousel", baseDataReqDto, BaseDataResDto.class);
    }
    
    /**
	 * 查看当天是否有正在助力的减肥基金
	 * @param maijiToken
	 * @return
	 */
    @PostMapping("isHaveReduceWeightFundLog")
    @ApiOperation(value = "查看当天是否有正在助力的减肥基金")
	public  BaseDataResDto<IsHaveReduceWeightFundLogResData> isHaveReduceWeightFundLog(@RequestHeader("maijiToken") String maijiToken)throws Exception{
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/isHaveReduceWeightFundLog", null, BaseDataResDto.class);
	}
    
    /**
	 * 用户领取减肥基金
	 * @param maijiToken
	 * @return
	 * @throws Exception
	 */
	@PostMapping("userDrawReduceWeightFund")
	@ApiOperation(value = "用户领取减肥基金")
	public BaseDataResDto<RecordWeightResData> userDrawReduceWeightFund(@RequestBody BaseDataReqDto<String> param,@RequestHeader("maijiToken") String maijiToken)throws Exception{
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/userDrawReduceWeightFund", param, BaseDataResDto.class);
	}
	
    
    
    /**
	 * 用户反馈
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("addAdviceFeedback")
	@ApiOperation(value = "用户反馈")
	public BaseResDto addAdviceFeedback(@RequestBody BaseDataReqDto<AdviceFeedbackReqData> param,@RequestHeader("maijiToken")String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/feedback/addAdviceFeedback", param, BaseResDto.class);
		
	}
	
	
	/**
	 * 意见反馈列表（分页）
	 * @param param
	 * @return
	 */
	@PostMapping("getAdviceFeedbackList")
	@ApiOperation(value = "意见反馈列表（分页）")
	public BaseDataResDto<List<AdviceFeedbackListResData>>  getAdviceFeedbackList(@RequestBody BaseDataReqDto<AdviceFeedbackListReqData> param,@RequestHeader("maijiToken")String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/feedback/getAdviceFeedbackList", param, BaseDataResDto.class);
	}
	/**
	 * 获取弹框信息
	 * @return
	 */
	@PostMapping("getUserStageMessageInfo")
	@ApiOperation(value = " 获取弹框信息")
	public BaseDataResDto<MessageInfoResData> getUserStageMessageInfo(@RequestHeader("maijiToken")String maijiToken)throws Exception{
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/getUserStageMessageInfo", null, BaseDataResDto.class);
	}
	/**
	 * 确认阶段弹框操作
	 * @param param
	 * @return
	 */
	@PostMapping("confirmMessageOperation")
	@ApiOperation(value = "弹框操作(data传值为弹框操作类型不是弹框类型)")
	public BaseDataResDto<String> confirmMessageOperation(@RequestBody BaseDataReqDto<Integer> param,@RequestHeader("maijiToken")String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/confirmMessageOperation", param, BaseDataResDto.class);
	} 
	
	/**
	 * 设置支付密码
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("setPayPassword")
	@ApiOperation(value = "设置支付密码")
	public BaseResDto setPayPassword(@RequestBody BaseDataReqDto<SetPayPasswordReqData> param,@RequestHeader("maijiToken") String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/setPayPassword", param, BaseResDto.class);
	}
	
	/**
	 * 修改支付密码
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("updatePayPassword")
	@ApiOperation(value = "修改支付密码")
	public BaseResDto updatePayPassword(@RequestBody BaseDataReqDto<UpdatePayPasswordReqData> param,@RequestHeader("maijiToken") String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/updatePayPassword", param, BaseResDto.class);
	}
	/**
	 * 校验支付密码是否正确
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("checkPayPassword")
	@ApiOperation(value = "校验支付密码是否正确")
	public BaseDataResDto<Boolean> checkPayPassword(@RequestBody BaseDataReqDto<String> param,@RequestHeader("maijiToken") String maijiToken){
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/checkPayPassword", param, BaseDataResDto.class);
	}
	
	/**
	 * 获取用户基本信息
	 * @param
	 * @return
	 * @throws Exception 
	 */
	@PostMapping("getUserById")
	@ApiOperation(value = "获取用户基本信息")
	public UserInfoResDto getUserById(@RequestBody BaseInputDto<IdInputDto> inputDto,@RequestHeader("maijiToken") String maijiToken){
		inputDto.getData().setToken(maijiToken);
		UserInfoResDto userInfoResDto = postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/getUserInfoWithUserId", inputDto, UserInfoResDto.class);
		
		if(userInfoResDto.getStatus().getValue() != 1 || userInfoResDto.getData() == null ) return userInfoResDto;
		
		BaseOutPutDto<Boolean>  baseOutPutDto = postForObjectWithToken(maijiToken, REST_URL_PREFIX_COMMUNITY + "/community/isFocusUser", inputDto, BaseOutPutDto.class);
		
		if(baseOutPutDto.getStatus().getValue() == 1)userInfoResDto.getData().setIsFollow(baseOutPutDto.getData());
		
		return userInfoResDto;
	}
	
	/**
	 * 结束麦吉之旅
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("endMaiji")
	@ApiOperation(value = " 结束麦吉之旅")
	public BaseResDto endMaiji(@RequestHeader("maijiToken")String maijiToken){
		
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/endMaiji", null, BaseResDto.class);
	}
	/**
	 * 开起麦吉之旅之后是否连续的记录体重
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("isSuccessionRecordWeight")
	@ApiOperation(value = "开起麦吉之旅之后是否未连续的记录体重")
	public BaseDataResDto<Boolean> isSuccessionRecordWeight(@RequestHeader("maijiToken")String maijiToken)throws Exception {
		
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/isSuccessionRecordWeight", null, BaseDataResDto.class);
	
     }
	
	/**
	 * 是否长时间未登录
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("isLongTimeNotLogIn")
	@ApiOperation(value = "是否长时间未登录")
	public BaseDataResDto<Boolean> isLongTimeNotLogIn(@RequestHeader("maijiToken")String maijiToken)throws Exception{
		
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/user/isLongTimeNotLogIn", null, BaseDataResDto.class);
	}
	
	@PostMapping("getDistributionTextContent")
	@ApiOperation(value = "关于分销文本内容")
	@Unlogin
	public BaseDataResDto<ActivityShareRuleConfigResData> getDistributionTextContent(@RequestHeader(value="maijiToken" ,required = false)String maijiToken){
		BaseDataReqDto param = new BaseDataReqDto();
		param.setData(CommonIntValueEnum.ACTIVITY_SHARE_RULE_CONFIG_TYPE_DISTRIBUTION.getValue());
		return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/maijiSettings/findShareRuleConfig", param, BaseDataResDto.class);
	}
	
	}
